package controleur;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;

import vue.WindowEditor;
/**
 * save the text been written in the textarea in  file "save.txt"
 * @author morhib & moyart
 *
 */
public class SaveControl implements ActionListener{

	WindowEditor w;	
	FileWriter writer;
	File file;

	public SaveControl(WindowEditor windowEditor) {
		this.w=windowEditor;
		file = new File("Save.txt");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		try {
			// create file
			writer = new FileWriter(file,true);
			// create a writer 
			try {
				writer.write(w.getTextArea().getText()+"\n");
			} finally {
				// close the file 
				writer.close();
			}
		} catch (Exception e1) {
			System.out.println("impossible to create the file");
		}
	}


}
